package com.share.finance.risk.rules.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.share.common.common.Page;
import com.share.finance.risk.rules.mapper.ReasonCodeMapper;
import com.share.finance.risk.rules.model.db.ReasonCode;
import com.share.finance.risk.rules.model.vo.ReasonCodePageReq;
import com.share.finance.risk.rules.service.IReasonCodeService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 原因代码库  服务实现类
 * </p>
 *
 * @author author
 * @since 2023-12-15
 */
@Service
public class ReasonCodeServiceImpl extends ServiceImpl<ReasonCodeMapper, ReasonCode> implements IReasonCodeService {
    @Resource
    private ReasonCodeMapper reasonCodeMapper;

    @Override
    public Page<ReasonCode> pageList(ReasonCodePageReq req) {
        PageHelper.startPage(req.getPageNum(), req.getPageSize());
        LambdaQueryWrapper<ReasonCode> queryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNotBlank(req.getCode())) {
            queryWrapper.like(ReasonCode::getCode, req.getCode());
        }
        if (StringUtils.isNotBlank(req.getDescript())) {
            queryWrapper.like(ReasonCode::getDescript, req.getDescript());
        }
        if (StringUtils.isNotBlank(req.getVarPrefix())) {
            queryWrapper.like(ReasonCode::getVarPrefix, req.getVarPrefix());
        }
        List<ReasonCode> list = reasonCodeMapper.selectList(queryWrapper);
        Page<ReasonCode> page = new Page<>(list, new PageInfo<>(list).getTotal(), req);
        return page;
    }
}
